{% extends "base.html" %}
{% block body %}

<div style="resize: vertical;margin-top:5px" class="card border-0 shadow" id="feed">
    <div class="card-header bg-header border border-dark shadow text-white">
        <h2 style="display:inline-block">Tasks By Tag</h2>
        <span style="display:inline-block; float:right">
            <span class="input-group" >
                <select class="form-control" v-model="selected_tag" style="width:auto;color:white" @change="selected_tag_changed" >
                    <option  v-for="o in tags" :value="o">[[o]]</option>
                </select>
                <template v-if="tasks.length > 0">
                    <button style="float:right;display:inline-block" class="btn btn{{config['outline-buttons']}}info btn-sm" @click="get_shareable_link()">Get Shareable Link</button>
                    <button style="float:right;display:inline-block" class="btn btn{{config['outline-buttons']}}danger btn-sm" @click="delete_tag()">Delete Tag</button>
                </template>
            </span>
        </span>
    </div>
    <div style="overflow-y:auto;padding:0;" class="card-body bg-card-body border border-dark shadow" >
        <div v-for="(task, index) in tasks" class="card-body response-background border border-dark shadow" style="word-wrap: break-word;padding:0;margin:0;">
            <div class="card-body response-background border border-dark shadow" style="word-wrap: break-word;padding:0;margin:0;">
                <template v-if="task['type'] === 'task'">
                    <div class="card-header border-dark bg-header-dark" :key="'headera' + task.id" style="position:-webkit-sticky;position:static;top:0;padding-bottom:0;padding-top:0px;padding-left:0;white-space:nowrap;overflow-x:auto;max-width:100%">
                        <transition-group>
                     <button v-if="task.comment != '' && task.comment_visible" :key="'keya' + task.id" class="btn btn{{config['outline-buttons']}}danger btn-sm" @click="remove_comment(task)" style="padding:0px 4px;margin-left:2px;margin-top:2px;border:0"><i class="fas fa-trash-alt"></i></button>
                     <p v-if="task.comment != '' && task.comment_visible" :key="'keyb' + task.id" class="card-text" style="margin:0;display:inline-block">
                        <small class="text-muted">[[task.comment_operator]]'s comment:</small></p>
                     <pre v-if="task.comment != '' && task.comment_visible" :key="'keyc' + task.id" style="padding-left:27px">[[task.comment]]</pre>
                     <hr v-if="task.comment != '' && task.comment_visible" :key="'keyd' + task.id" style="margin-bottom: 0;margin-top:6px">

                     <div class="btn-group dropdown" :key="'statusdropdown' + task.id" style="display:inline-block;">
                        <template v-if="task.opsec_pre_blocked === true && task.opsec_pre_bypassed === false">
                                 <button class="btn btn{{config['outline-buttons']}}warning btn-sm dropdown-toggle" style="border:0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="card-text">OPSEC BLOCKED (PRE)</span></button>
                             </template>
                             <template v-else-if="task.opsec_post_blocked === true && task.opsec_post_bypassed === false">
                                 <button class="btn btn{{config['outline-buttons']}}warning btn-sm dropdown-toggle" style="border:0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="card-text">OPSEC BLOCKED (POST)</span></button>
                             </template>
                            <template v-else-if="task.status.includes('error')">
                                <button class="btn btn{{config['outline-buttons']}}danger btn-sm dropdown-toggle"  style="border:0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="card-text">[[task.status]]</span></button>
                            </template>
                            <template v-else-if="task.completed == true || task.status === 'completed'">
                                <button class="btn btn{{config['outline-buttons']}}success btn-sm dropdown-toggle" style="border:0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="card-text">completed</span></button>
                            </template>
                            <template v-else-if="task.status == 'processed'">
                                <button class="btn btn{{config['outline-buttons']}}primary btn-sm dropdown-toggle"  style="border:0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="card-text">[[task.status]]</span></button>
                            </template>
                            <template v-else-if="task.status == 'processing' || task.status == 'cleared'">
                                <button class="btn btn{{config['outline-buttons']}}warning btn-sm dropdown-toggle"  style="border:0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="card-text">[[task.status]]</span></button>
                            </template>

                            <template v-else>
                                <button class="btn btn{{config['outline-buttons']}}info btn-sm dropdown-toggle"  style="border:0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="card-text">[[task.status]]</span></button>
                            </template>
                        <div class="dropdown-menu" style="z-index:9999">
                            <a class="dropdown-item" href="#" data-toggle="tooltip" title="Add comment to task" @click="add_comment(task)"><i class="fas fa-comments"></i> Comment</a>
                            <a class="dropdown-item" href="#" data-toggle="tooltip" title="download raw output" @click="download_raw_output(task.id)"><i class="fas fa-save"></i> Save Output</a>
                            <a class="dropdown-item" href="#" data-toggle="tooltip" title="Copy command to clipboard" @click="copyStringToClipboard(task.command + ' ' + task.original_params)"><i class="far fa-copy" ></i> Copy Command</a>
                            <a class="dropdown-item" href="#" data-toggle="tooltip" title="Toggle application of browser scripts to output of this task" @click="task.use_scripted = !task.use_scripted"><i class="fas fa-code"></i>
                                <template v-if="task.use_scripted">
                                    Disable Browser Script
                                </template>
                                <template v-else>
                                    Enable Browser Script
                                </template>
                            </a>
                            <a class="dropdown-item" href="#" data-toggle="tooltip" title="View Stdout/Stderr for task" @click="view_stdout_stderr(task)"><i class="fas fa-info-circle"></i>View Task Stdout/Stderr</a>
                            <a class="dropdown-item" href="#" data-toggle="tooltip" title="View all parameters for task" @click="view_all_parameters(task)"><i class="fas fa-info-circle"></i>View All Parameters</a>
                            <a class="dropdown-item" href="#" data-toggle="tooltip" title="View/Edit all tags for task" @click="view_all_tags(task)"><i class="fas fa-edit"></i>View/Edit Tags</a>
                            <template v-if="task.opsec_pre_blocked !== null || task.opsec_post_blocked !== null">
                                <a class="dropdown-item" href="#" data-toggle="tooltip" title="View OPSEC block info" @click="view_opsec_block(task)"><i class="fas fa-info-circle"></i>View OPSEC Message</a>
                            </template>
                            <template v-if="task.opsec_pre_blocked && task.opsec_pre_bypassed === false">
                                <a class="dropdown-item" href="#" data-toggle="tooltip" title="submit bypass request" @click="submit_opsec_bypass_request(task)"><i class="fas fa-info-circle"></i>Submit Bypass Request ([[task.opsec_pre_bypass_role]])</a>
                            </template>
                            <template v-else-if="task.opsec_post_blocked && task.opsec_post_bypassed === false">
                                <a class="dropdown-item" href="#" data-toggle="tooltip" title="submit bypass request" @click="submit_opsec_bypass_request(task)"><i class="fas fa-info-circle"></i>Submit Bypass Request ([[task.opsec_post_bypass_role]])</a>
                            </template>
                            <template v-if="task.status === 'error: container down'">
                                <a class="dropdown-item" href="#" data-toggle="tooltip" title="re-issue request" @click="reissue_request(task)"><i class="fas fa-info-circle"></i> Re-issue task</a>
                            </template>
                        </div>
                    </div>
                     <p :key="'mutedtext' + task.id" class="card-text" style="margin:0;padding-left:5px; display:inline-block"><small class="text-muted">
                        [[task.operator]]'s task: <a :href="'{{http}}://{{links.server_ip}}:{{links.server_port}}/tasks/' + task.id" target="_blank" data-toggle="tooltip" title="View task and output in a separate window">[[task.id]] </a> <template v-if="task.parent_task !== null">(subtask of <a :href="'{{http}}://{{links.server_ip}}:{{links.server_port}}/tasks/' + task.parent_task" target="_blank" data-toggle="tooltip" title="View task and output in a separate window">[[task.parent_task]]</a>)</template>
                        - at [[toLocalTime(task.timestamp)]]
                     </small></p>
                     <a :key="'commentdots' + task.id" v-if="task.comment !== ''" style="padding-bottom:0" class="btn btn-link" type="button" @click="toggle_comment(task)"><i class="far fa-comment-dots" ></i></a>
                     <br :key="'br' + task.id">
                     <a :key="'toggleoutput' + task.id" class="btn btn-link" type="button" style="border:0;padding:0 0 5px 5px" data-toggle="collapse" :data-target="'#cardbody' + task.id" aria-expanded="false" :aria-controls="'cardbody' + task.id" @click="toggle_arrow(task)"><i :id="'color-arrow' + task.id" class="fas fa-plus fa-xs" data-toggle="tooltip" title="view / hide task output"></i></a>
                        <div style="display:inline-block" :key="'taskcommand' + task.id"><b>&nbsp;[[task.command]]&nbsp;</b></div>
                     <div style="display:inline-block" :key="'taskparams' + task.id">[[task.display_params]]</div>
                    </transition-group>
                    </div>
                    <div :key="'outputcontent' + task.id" class="collapse" :id="'cardbody' + task.id" >
            <div :key="'outputcontentcardbody' + task.id" class="response-background card-body shadow" style="padding-top:0;padding-bottom: 0" >
                <div :key="'showparams' + task.id" v-if="task.show_params">
                    Modified Parameters: &nbsp;[[task.params]]
                </div>
                <span :key="'usescripted' + task.id" v-if="task.hasOwnProperty('scripted') && task.use_scripted" v-html="task.scripted"></span>
                <span v-else :key="'useregular' + task.id" class="card-text" v-for="rsp in task.response" :key="rsp.id" :id="'response' + rsp.id" style="white-space: pre-wrap"><span class="response"><pre>[[rsp.response]]</pre></span></span>
            </div>
    </div>
                </template>
                <template v-else>
                    <h5 style="padding-left:10px;display:inline-block"><template v-if="task['domain'] !== ''">[[task.domain]]\</template>[[task.user]]<template v-if="task['integrity_level'] > 2">*</template>@[[task.host]] (<a :href="'{{http}}://{{links.server_ip}}:{{links.server_port}}/split_callbacks/' + task.id" target="_blank">[[task.id]]</a>)</h5>
                 </template>
        </div>
        </div>
    </div>
    <div v-if="artifacts.length > 0" class="card border border-dark shadow bg-card-body" id="task_artifacts" style="overflow-y:auto;margin-top:5px">
        <div class="card-header bg-header border border-dark shadow text-white">
            <h2><span class="operator">Task</span> Artifacts</h2>
        </div>
        <div class="card-body response-background border border-dark shadow" style="word-wrap: break-word;padding:0;margin:0;">
            <table class="table table-striped {{config['table-color']}}">
                <tr>
                    <th onclick="sort_table(this)" style="text-align:left"><b>Task</b></th>
                    <th onclick="sort_table(this)" style="text-align:left"><b>Type</b></th>
                    <th onclick="sort_table(this)" style="text-align:left"><b>Artifact</b></th>
                </tr>
                <!-- Repeat this for each base artifact -->
                <tr v-for="(artifact, i) in artifacts" :key="artifact.id">
                    <td style="padding-left:10px; width:8rem"><a :href="'{{http}}://{{links.server_ip}}:{{links.server_port}}/tasks/' + artifact.task_id" target="_blank">[[artifact.task_id]]</a></td>
                    <td style="padding-left:10px">[[ artifact.artifact ]]</td>
                    <td>[[ artifact.artifact_instance ]]</td>
                </tr>
            </table>
        </div>
    </div>
    <div v-if="files.length > 0" class="card border border-dark shadow bg-card-body"  style="overflow-y:auto;margin-top:5px">
        <div class="card-header bg-header border border-dark shadow text-white">
            <h2><span class="operator">Task</span> Files/Screenshots</h2>
        </div>
        <div class="card-body response-background border border-dark shadow" style="word-wrap: break-word;padding:0;margin:0;">
            <table class="table table-striped {{config['table-color']}}">
                <tr>
                    <th onclick="sort_table(this)" style="text-align:left"><b>Filename</b></th>
                    <th onclick="sort_table(this)" style="text-align:left"><b>Type</b></th>
                    <th onclick="sort_table(this)" style="text-align:left"><b>Remote Path</b></th>
                    <th onclick="sort_table(this)" style="text-align:left"><b>Comment</b></th>
                    <th onclick="sort_table(this)" style="text-align:left"><b>Hashes</b></th>
                </tr>
                <!-- Repeat this for each base artifact -->
                <tr v-for="(file, i) in files" :key="file.id">
                    <td style="padding-left:10px">
                        <template v-if="!file.deleted">
                            <template v-if="file.total_chunks != file.chunks_received">
                                [[file.filename]] <span class="display">Parts [[file.chunks_received]] of [[file.total_chunks]] received so far</span>
                            </template>
                            <template v-else>
                                <a style="cursor:pointer;color:{{config['text-color']}};text-decoration:underline" :href="'{{http}}://{{links.server_ip}}:{{links.server_port}}{{links.api_base}}/files/download/' + file['agent_file_id']">[[ file.filename ]]</a>
                            </template>
                         </template>
                        <template v-else>
                            [[ file.filename ]]
                        </template>

                    </td>
                    <td>
                        <template v-if="file.is_payload">Payload</template>
                        <template v-else-if="file.is_screenshot">Screenshot</template>
                        <template v-else-if="file.is_download_from_agent">Download</template>
                        <template v-else>Upload</template>
                    </td>
                    <td>
                        <template v-if="file.full_remote_path !== ''">
                            [[file.host]] : [[file.full_remote_path]]
                        </template>
                    </td>
                    <td>[[file.comment]]</td>
                    <td>MD5: [[ file.md5 ]]<br/>SHA1: [[file.sha1]]</td>
                </tr>
            </table>
        </div>
    </div>
    <div v-if="credentials.length > 0 " class="card border border-dark shadow bg-card-body" id="task_credentials" style="overflow-y:auto;margin-top:5px">
        <div class="card-header bg-header border border-dark shadow text-white">
            <h2><span class="operator">Task</span> Credentials</h2>
        </div>
        <div class="card-body response-background border border-dark shadow" style="word-wrap: break-word;padding:0;margin:0;">
            <table class="table table-striped {{config['table-color']}}">
                <tr>
                    <th onclick="sort_table(this)" style="text-align:left;width:10rem"><b>Type</b></th>
                    <th onclick="sort_table(this)" style="text-align:left"><b>Account</b></th>
                    <th onclick="sort_table(this)" style="text-align:left"><b>Realm</b></th>
                    <th onclick="sort_table(this)" style="text-align:left"><b>Credential</b></th>
                    <th onclick="sort_table(this)" style="text-align:left"><b>Comment</b></th>
                </tr>
                <!-- Repeat this for each base artifact -->
                <tr v-for="(cred, i) in credentials" :key="cred.id">
                    <td style="padding-left:10px">[[ cred.type ]]</td>
                    <td>[[ cred.account ]]</td>
                    <td>[[ cred.realm ]]</td>
                    <td>[[ cred.credential ]]</td>
                    <td>[[ cred.comment ]]</td>
                </tr>
            </table>
        </div>
    </div>
    <div v-if="attack.length > 0" class="card border border-dark shadow bg-card-body"  style="overflow-y:auto;margin-top:5px">
        <div class="card-header bg-header border border-dark shadow text-white">
            <h2><span class="operator">Task</span> MITRE ATT&CK Mappings</h2>
        </div>
        <div class="card-body response-background border border-dark shadow" style="word-wrap: break-word;padding:0;margin:0;">
            <table class="table table-striped {{config['table-color']}}">
                <tr>
                    <th onclick="sort_table(this)" style="text-align:left;width:10rem"><b>Technique ID</b></th>
                    <th onclick="sort_table(this)" style="text-align:left"><b>Technique</b></th>
                </tr>
                <!-- Repeat this for each base artifact -->
                <tr v-for="(attck, i) in attack" :key="attck.id">
                    <td style="padding-left:10px">[[ attck.attack ]]</td>
                    <td>[[ attck.attack_name ]]</td>
                </tr>
            </table>
        </div>
    </div>
</div>
<!-- THIS IS OUR MODAL FOR ADDING A COMMENT -->
<div class="modal fade" id="addCommentModal" role="dialog" >
    <div class="modal-dialog modal-xl" role="document">
        <div class="modal-content">
            <div class="modal-header bg-dark text-white">
                <h3>Add / Edit Comment</h3>
                <button type="button" class="close" data-dismiss="modal">×</button>
            </div>
            Shift+Enter to add a new line, Enter to submit
              <div class="modal-body">
                <textarea class="form-control" rows="25" style="width:100%" id="addCommentTextArea"></textarea>
              </div>
              <div class="modal-footer">
                <button class="btn btn{{config['outline-buttons']}}success" data-dismiss="modal" id="addCommentSubmit" aria-hidden="true">Submit</button>
              </div>
        </div>
    </div>
</div>
<!-- END MODAL FOR ADDING A COMMENT -->
<!-- THIS IS OUR MODAL FOR ADDING A TAG -->
<div class="modal fade" id="addTagModal" role="dialog" >
    <div class="modal-dialog modal-xl" role="document">
        <div class="modal-content" id="addTagModalData">
            <div class="modal-header bg-dark text-white">
                <h3>Add / Edit Tags</h3>
                <button type="button" class="close" data-dismiss="modal">×</button>
            </div>
            Shift+Enter to add a new line when manually entering, or click "+" to add the selected tag:
            <span class="input-group" >
                <select class="form-control" v-model="selected_tag" style="width:auto;display:inline-block">
                    <option  v-for="o in tags" :value="o">[[ o ]]</option>
                </select>
                <button style="display:inline-block;float:right" class="btn btn-sm btn{{config['outline-buttons']}}success" @click="task_info.add_tag()"><i class="fas fa-plus"></i></button>
            </span>
          <div class="modal-body">
            <textarea class="form-control" rows="25" style="width:100%"  v-model="current_tags" id="addTagTextArea"></textarea>
          </div>
          <div class="modal-footer">
              <button class="btn btn{{config['outline-buttons']}}warning" data-dismiss="modal" aria-hidden="true">Cancel</button>
            <button class="btn btn{{config['outline-buttons']}}success" data-dismiss="modal" id="addTagSubmit" aria-hidden="true">Submit</button>
          </div>
        </div>
    </div>
</div>
<!-- END MODAL FOR ADDING A TAG -->
<!-- THIS IS OUR MODAL FOR DELETING TAG -->
<div class="modal fade" id="tagDeleteModal" role="dialog">
    <div class="modal-dialog modal-md" role="document">
        <div class="modal-content">
            <div class="modal-header bg-dark text-white">
                <h3 id="modalLabel">Are you sure?</h3>
                <button type="button" class="close" data-dismiss="modal">×</button>
            </div>
              <div class="modal-footer">
                <button class="btn btn{{config['outline-buttons']}}warning" data-dismiss="modal" aria-hidden="true">Cancel</button>
                <button class="btn btn{{config['outline-buttons']}}danger" data-dismiss="modal" id="tagDeleteSubmit">Submit</button>
              </div>
        </div>
    </div>
</div>
<!-- END MODAL FOR DELETING TAG -->
{% endblock %}

{% block scripts %}
{% include "task_tags_view.js" %}
{% endblock %}

{% block body_config %}
.btn.disabled, .btn:disabled {
    opacity: 1 !important;
}
{% endblock %}